<?php
declare(strict_types=1);

namespace App\Models;

use Illuminate\Database\Eloquent\Relations\BelongsTo;

class Author extends BaseModel
{
    protected $table = "author";

    protected $fillable = [
        "uid",
        "user_uid",
        "nickname",
        "is_forbidden",
        "series_count",
        "qr_url",
        "created_at",
        "updated_at",
        "remark",
        "birthday",
        "gender",
        "profession",
        "audit_at",
        "audit_msg",
        "audit_id",
        "audit_status",
        "constellation",
    ];

    protected $casts = [
        "user_uid" => "string",
        "profession" => "string",
        "uid" => "string",
    ];

    public function getConstellationAttribute($key): string
    {
        return empty($key) ? "星座未知" : $key;
    }

    public function profession(): BelongsTo
    {
        return $this->belongsTo(UserProfession::class, "profession", "uid");
    }

    public function user(): BelongsTo
    {
        return $this->belongsTo(User::class, "user_uid", "uid");
    }

    public function getBirthdayAttribute($key): string
    {
        return !empty($key) ? $key : "";
    }

    public function getNicknameAttribute($key): string
    {
        return !empty($key) ? $key : "";
    }

    public function getAuditAtAttribute($key): string
    {
        return !empty($key) ? $key : "";
    }

    public function getAuditMsgAttribute($key): string
    {
        return !empty($key) ? $key : "";
    }
}
